<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
// 应用公共文件
use think\Db;
function get_token() {
    $server_id = '001';
    $time = getMillisecond();
    $token = $time . $server_id;
    $id = Db::name("token_id")->insertGetId(['token' => $token]);
    $rand = rand(1000, 9999);
    $token = $time . $server_id . $id;
    Db::name("token_id")->where('id', $id)->update(['token' => $token]);
    return $token;
}
function getMillisecond() {
    list($t1, $t2) = explode(' ', microtime());
    return (float) sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
}
function get_table_comment($table){
    $table=Db::name($table)->getTable();
    $re=Db::query("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '".$table."'");
    $comments=[];
    if(is_array($re)){
        foreach ($re as $key=>$item){
            if($item['COLUMN_COMMENT']){
                $comments[$item['COLUMN_NAME']]=$item;
            }else{
                $item['COLUMN_COMMENT']=$item['COLUMN_NAME'];
                $comments[$item['COLUMN_NAME']]=$item;
            }

        }
    }else{
        return false;
    }

    return $comments;
}